/* GSBusOrderResolveReceiveSaveAction.java
 *
 * Project/Product: JZCG-SHBUS
 *
 * Modify Information:
 * =============================================================================
 *   Author	Date       Description
 *   ----------	---------- ---------------------------------------------------
 *   wp	2008-1-24	First release
 *
 * Licensed Materials - Property of APEP
 * =============================================================================
 *    (C) COPYRIGHT Shanghai Auto Mart E-Procurement Co., Ltd. 2007 - 2008
 *    All Rights Reserved.
 *
 *    This software is the confidential and proprietary information of
 *    Shanghai Auto Mart E-Procurement Co., Ltd. ("Confidential Information").
 *    You shall not disclose such Confidential Information and shall use it only
 *    in accordance with the terms of the license agreement you entered into 
 *    with Shanghai Auto Mart E-Procurement Co., Ltd.
 *
 * Noties:
 * =============================================================================
 * 
 */

package com.hitrust.gs.action;

import java.util.ArrayList;

import system.LoginContext;

import com.hitrust.gs.bean.GSManufactureBean;
import com.hitrust.gs.bean.GSOrderAnaDetailAndCategoryBean;
import com.hitrust.gs.bean.GSProviderBean;
import com.hitrust.gs.business.GSCommunicationApepProcessor;
import com.hitrust.gs.dao.GSManufactureDAO;
import com.hitrust.gs.dao.GSOrderDetailDAO;
import com.hitrust.gs.dao.GSProviderDAO;
import com.hitrust.gs.form.GSOrderSubmitForm;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.service.GSBaseAction;
import com.hitrust.gs.service.GSBaseForm;

public class GSBusOrderResolveReceiveSaveNewAction extends GSBaseAction {

    /* (non-Javadoc)
     * @see com.hitrust.gs.service.GSBaseAction#execute(com.hitrust.gs.service.GSBaseForm)
     */
    public String execute(GSBaseForm aForm) throws Exception {
    	GSManufactureDAO dao = new GSManufactureDAO();
		LoginContext context = (LoginContext) aForm.getSession().getAttribute(
				GSBaseConstants.LOGIN);
	   	GSOrderDetailDAO detailDao=new GSOrderDetailDAO();
	   	GSProviderDAO providerDao=new GSProviderDAO();
        int totalCount = Integer.parseInt(aForm.getRequest().getParameter("totalCount"));

        String tRs = "";
        String strs ="";
        for(int i=0; i<totalCount; i++) {
            
            String[] tStr = new String[6];
            tStr[0] = aForm.getRequest().getParameter("signOrderDetailId_"+i);
            tStr[1] = aForm.getRequest().getParameter("signQty_"+i);
            tStr[2] = aForm.getRequest().getParameter("signDate_"+i);
            tStr[3] = aForm.getRequest().getParameter("signPrice_"+i);
            tStr[4] = aForm.getRequest().getParameter("remark_"+i);
            strs = aForm.getRequest().getParameter("flag_"+i);
            
            GSOrderAnaDetailAndCategoryBean orderDetail = detailDao.getOrderDetailByDetailId(tStr[0]);
    		GSManufactureBean bean=dao.getManufactureByConcentricityCode(orderDetail.getGs_concentricity_id());
    		GSProviderBean provider=providerDao.queryProvider(orderDetail.getGs_provider_id());
    		
    		if("Y".equals(strs)){
    	             dao.updateOrderDetail(GSBaseConstants.ORDER_ORDER_REJECT,tStr[4],
    	            		new framework.core.DateUtil().getDateString(),
    	            		new framework.core.DateUtil().getTimeString(),tStr[0]);
    		}else{
    			   if("Y".equals(tStr[3])){
    	            	dao.updateOrderGoods(GSBaseConstants.ORDER_DELIVERY_CONFIRM, new framework.core.DateUtil().getDateString(),
    	            			new framework.core.DateUtil().getTimeString(),orderDetail.getGs_order_count()+"",context.getLoginUserName(),tStr[4], tStr[0]);
    	            	dao.insertOrderDetailSignIn(new framework.core.DateUtil().getDateString(), new framework.core.DateUtil().getTimeString(),
    	            			orderDetail.getGs_order_count()+"", tStr[1], context.getLoginUserName(),  tStr[4] ,  tStr[0],bean,provider);
    	            }else{
    	              	dao.updateOrderGoodsNo(new framework.core.DateUtil().getDateString(),
    	            			new framework.core.DateUtil().getTimeString(),
    	            			(orderDetail.getGs_signin_count()+Double.parseDouble(tStr[1]))+"",
    	            			context.getLoginUserName(), tStr[4], tStr[0]);
    	            	dao.insertOrderDetailSignIn(new framework.core.DateUtil().getDateString(), new framework.core.DateUtil().getTimeString(),
    	            			orderDetail.getGs_order_count()+"", tStr[1], context.getLoginUserName(),  tStr[4] ,  tStr[0],bean,provider);
    	            }
    		}
    		
         

        }
        
        return GSBaseConstants.FORWARD_SUCCESS;
    }

}
